<?php


namespace App\Model;


/**
 * App\Model\Address
 *
 * @property int $id
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property int $user_id 地址所有者
 * @property string $name 收货人
 * @property string $phone 手机号
 * @property string $address 地址
 * @property string $address_index 表单选中下标
 * @property string $address_detail 详细地址
 * @property string $label 标签
 * @property int $is_default 是否是默认地址，1是2否
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Address newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Address newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Address query()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Address whereAddress($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Address whereAddressDetail($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Address whereAddressIndex($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Address whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Address whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Address whereIsDefault($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Address whereLabel($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Address whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Address wherePhone($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Address whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Address whereUserId($value)
 * @mixin \Eloquent
 */
class Address extends Base
{

    protected $table='address';

    protected $fillable=['user_id','name','phone','address','address_index','address_detail','label','is_default'];



    function setAddressIndexAttribute($value)
    {

        if(!$value) return $this->attributes['address_index']='';

        if(!is_array($value)) return $this->attributes['address_index']='';


        $this->attributes['address_index']=join(',',$value);

    }


    function getAddressIndexAttribute($value){

        if(!$value) return [];

        return explode(',',$value);

    }

}
